package top.zhangjianyong.tools.timer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import top.zhangjianyong.tools.utils.DaChenUtil;
import top.zhangjianyong.tools.utils.MailUtil;
import top.zhangjianyong.tools.utils.StringBuildUtil;

import javax.validation.constraints.Email;
import java.util.Map;

/**
 * @author ： zhangjianyong
 * @date ： 2023/7/20 01:57
 */
@Slf4j
@Component
public class DaChenTimer {

    //@Scheduled(cron = "0 */1 * * * ?")
    public static void doTimer() {

        Map<String, Integer> map = DaChenUtil.ticketMap();

        StringBuilder sb = new StringBuilder();
        sb.append("大陈岛船票提醒!!! ");
        StringBuilder content = new StringBuilder();
        Integer qd9 = map.get("QD9X1-庆达9");
        content.append("QD9X1-庆达9 余票：").append(qd9).append("\n");
        boolean flag = false;
        if (qd9 < 15) {
            flag = true;
            sb.append("7：30 庆达9余票小于15张\n");
        }
        Integer dsz = map.get("DZSXX-东镇山");
        content.append("DZSXX-东镇山 余票：").append(dsz).append("\n");
        if (dsz < 50) {
            flag = true;
            sb.append("8:00 东山镇余票小于50张\n");
        }
        Integer qd8 = map.get("HJXX1-庆达8");
        content.append("HJXX1-庆达8 余票：").append(qd8).append("\n");
        if (qd8 > 0) {
            flag = true;
            sb.append("8:40 庆达8余票大于0!!!\n");
        }

        try {
            if (flag) {
                MailUtil.send("605600162@qq.com", sb.toString(), content.toString());
                MailUtil.send("1506018710@qq.com", sb.toString(), content.toString());

            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

    }
}
